<?php
/**
 * 
 * @author tangbl
 *
 */
class UserModel extends Model {
	
	/*array(
		0.字段名   
		1.验证规则 [require 字段必须、email 邮箱、url URL地址、currency 货币、number 数字]
		2.提示信息  {%usr_form_validata_email_email}
		3.验证条件 [0.(默认)存在字段就验证;1.必须验证;2.值不为空的时候验证]
		4.附加规则 [regex、function、callback、confirm、equal、in、length、between、expire、ip_allow、ip_deny、unique]
		5.验证时   [1.新增数据时候验证;2.编辑数据时候验证;3.(默认)全部情况下验证]
	);*/
	protected $_validate    =   array(
		array('username','require','{%usr_form_validata_username_required}',1,'',1),
		array('username','','{%usr_form_validata_username_exsits}',1,'unique',1),
		array('email','email','{%usr_form_validata_email_email}',1),
		array('sex',array(1,2),'{%cfg_form_tipmsg_illgel}',1,'in',3),
		array('status',array(1,2),'{%cfg_form_tipmsg_illgel}',1,'in',3),
		array('role','number','{%usr_form_validata_role_required}',1,'',3),
		//array('repassword','password','{%usr_form_validata_password_re_regex}',0,'confirm',3), // 验证确认密码是否和密码一致
	);
	// 定义自动完成
	protected $_auto    =   array(
		array('addtime','time',1,'function'),//add
		array('password','myencrypt',1,'function'),//add
		array('solevar','create_id',1,'function')
	);
	
	// 获取所有用户信息
	public function getAllUser($where = '' , $order = 'id  ASC', $limit='') {
		return $this->where($where)->order($order)->limit($limit)->select();
	}
	
	//获取所有角色信息
	public function getAllRole($where = '' , $order = 'id  ASC', $limit=''){
		$role = M("Role");
		return $role->where($where)->order($order)->select();
	}
	
	public function getRoleName($roleId){
		$role  = M("Role");
		$name  = $role->where("id=$roleId")->getField("name");
		return $name;
	}
	
}
?>